#include "lp87524.h"
#include "i2c.h"
#include <stdio.h>

#define ADDR6416 0x20<<1

static int pca6416gpio(uint16_t val)
{
    static uint8_t data[3] = {2, 0, 0};
    int Status;

    data[1] = (val >> 8);
    data[2] = (uint8_t)val;

    Status = HAL_I2C_Master_Transmit(&hi2c2, ADDR6416, data, 3, 0xff);
    return Status;
}

int pca6416init()
{
    static uint8_t data[3] = {6, 0x00, 0x00};
    int Status = 0;
    Status |= HAL_I2C_Master_Transmit(&hi2c2, ADDR6416, data, 3, 0xff);

    Status |= pca6416gpio(0x00);
    printf("pca6416init=%d\r\n", Status);

    return Status;
}

int PWR_ON()
{
    int Status = 0;

    Status |= pca6416gpio(0x4900); // 0B 0100 1001
    //HAL_Delay(1);
    Status |= pca6416gpio(0xff00); // 0B 1111 1111

    return Status;
}

int PWR_OFF()
{
    int Status = 0;

    Status |= pca6416gpio(0x00); // 0B 0100 1001

    return Status;
}
